#include <QVBoxLayout>
#include <QDebug>
#include "EditorContainer.h"
#include "StatusBar.h"
#include "TextEditor.h"

namespace Plugins
{

EditorContainer::EditorContainer(TextEditor *edit, QWidget *parent, Project * prj):
    QWidget(parent),
    _edit(edit)
{
    setLayout(new QVBoxLayout());
    layout()->setContentsMargins(0, 0, 0, 0);
    layout()->setSpacing(0);
    _bar = new StatusBar(this);
    edit->setStatusBar(_bar);
    edit->setProject(prj);
    layout()->addWidget(_bar);
    layout()->addWidget(edit->widget());

    connect(_edit->widget(), SIGNAL(copyAvailable(bool)), SIGNAL(copyAvailable(bool)));
    connect(_edit->widget(), SIGNAL(undoAvailable(bool)), SIGNAL(undoAvailable(bool)));
    connect(_edit->widget(), SIGNAL(redoAvailable(bool)), SIGNAL(redoAvailable(bool)));
    connect(_edit->widget(), SIGNAL(copyAvailable(bool)), SIGNAL(copyAvailable(bool)));
    connect(_edit->widget(), SIGNAL(modificationChanged(bool)), SIGNAL(modifyChanged(bool)));
    connect(_edit->widget(), SIGNAL(severityChanged(int)), SIGNAL(severityChanged(int)));
    connect(_edit->widget(), SIGNAL(errorListChanged(QAbstractTableModel*)), SIGNAL(errorListChanged(QAbstractTableModel*)));
    connect(_edit->widget(), SIGNAL(fileNavigate(QString, int)), SIGNAL(fileNavigate(QString, int)));
    connect(_bar, SIGNAL(closeRequest()), SIGNAL(closeEditor()));
}

EditorContainer::~EditorContainer()
{
    delete _edit;
}

QWidget * EditorContainer::widget()
{
    return this;
}

QsciLexer * EditorContainer::getLexer()
{
    return _edit->getLexer();
}

void EditorContainer::setLexerByName(const QString& lexName)
{
    _edit->setLexerByName(lexName);
}

bool EditorContainer::save()
{
    return _edit->save();
}

bool EditorContainer::load(const QString & path)
{
    return _edit->load(path);
}

void EditorContainer::setText(const QString& text)
{
    _edit->setText(text);
}

void EditorContainer::setTheme(ITheme * theme, QFont * fnt)
{
    _edit->setTheme(theme, fnt);
}

void EditorContainer::activate()
{
    _edit->activate();
}

QString EditorContainer::selectedText()
{
    return _edit->selectedText();
}

void EditorContainer::find(const QString& find, bool forward)
{
    _edit->find(find, forward);
}

void EditorContainer::replace(const QString& find, const QString& replace, bool findNext, bool forward)
{
    _edit->replace(find, replace, findNext, forward);
}

void EditorContainer::replaceAll(const QString& find, const QString& replace)
{
    _edit->replaceAll(find, replace);
}

void EditorContainer::undo()
{
    _edit->undo();
}

void EditorContainer::redo()
{
    _edit->redo();
}

void EditorContainer::copy()
{
    _edit->copy();
}

void EditorContainer::cut()
{
    _edit->cut();
}

void EditorContainer::paste()
{
    _edit->paste();
}

void EditorContainer::del()
{
    _edit->del();
}

void EditorContainer::selectAll()
{
    _edit->selectAll();
}

void EditorContainer::uppercase()
{
    _edit->uppercase();
}

void EditorContainer::lowercase()
{
    _edit->lowercase();
}

void EditorContainer::capitalize()
{
    _edit->capitalize();
}

void EditorContainer::focusInEvent(QFocusEvent *)
{
    _edit->setFocus();
}

bool EditorContainer::isModified()
{
    return _edit->isModified();
}

bool EditorContainer::reset()
{
    return _edit->reset();
}

void EditorContainer::addRightPanel(QWidget */*panel*/)
{

}

void EditorContainer::jumpLine(int lineNo)
{
    _edit->jumpLine(lineNo);
}

void EditorContainer::jumpOffset(int offset)
{
    _edit->jumpOffset(offset);
}

void EditorContainer::setStatusBarVisible(bool show)
{
    if (_bar) _bar->setVisible(show);
}

}
